using System;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

using OpenNetCommerce.Localization;

namespace MettleSystems.dashCommerce.Web {
  public partial class login : MettleSystems.dashCommerce.Controls.BasePage {

    #region Page Events

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e) {
      Button btnLogin = llogin.FindControl("LoginButton") as Button;
      if (btnLogin != null)
        Page.Form.DefaultButton = btnLogin.UniqueID;

      SetLoginControlProperties();
    }

    #endregion

    #region Methods

    #region Protected

    /// <summary>
    /// Sets the cookie.
    /// </summary>
    /// <param name="sender">The sender.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void SetCookie(object sender, EventArgs e) {
      if (Membership.ValidateUser(llogin.UserName, llogin.Password)) {
        FormsAuthentication.SetAuthCookie(llogin.UserName, ((CheckBox)llogin.FindControl("RememberMe")).Checked);
      }
    }

    #endregion

    #region Private

    /// <summary>
    /// Sets the login control properties.
    /// </summary>
    private void SetLoginControlProperties() {
      //this.Title = string.Format(WebUtility.MainTitleTemplate, Master.SiteSettings.SiteName, LocalizationUtility.GetText("titleLogin"));
    	//this.LocalizedTitleKey = "titleLogin"; // not needed; it will be computed by BasePage
      llogin.UserNameLabelText = LocalizationUtility.GetText("lloginUserNameLabelText");
      llogin.PasswordLabelText = LocalizationUtility.GetText("lloginPasswordLabelText");
      llogin.TitleText = LocalizationUtility.GetText("lloginTitleText");
      llogin.PasswordRecoveryText = LocalizationUtility.GetText("lloginPasswordRecoveryText");
      llogin.CreateUserText = LocalizationUtility.GetText("lloginCreateUserText");
    }

    #endregion

    #endregion

  }
}
